<?php
/**
 * alltosun.com  test_helper.php
 * ============================================================================
 * 版权所有 (C) 2009-2013 北京互动阳光科技有限公司，并保留所有权利。
 * 网站地址: http://www.alltosun.com
 * ----------------------------------------------------------------------------
 * 许可声明：这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
 * ============================================================================
 * $Author: 王德康 (wangdk@alltosun.com) $
 * $Date: 2015-12-14 下午6:14:09 $
 * $Id$
 */
class Action
{
    
    private $per_page = 20;
    
    /**
     * 执行发送
     */
    public function send()
    {
        
    }
    
    /**
     * 添加页面
     */
    public function add()
    {
        Response::assign('sign_name_list', aliysms_config::$sign_name_list);
        Response::display('admin/add.html');
    }
    
    /**
     * 添加到数据库
     */
    public function create()
    {
        //接受
        $sms = Request::getParam('sms', array());
//         an_dump($sms);
        $send_res = false;
        switch ($sms['sign_name']) {
        	case 'recover_password':
        	    $send_res = aliysms_helper::send_forgot_password($sms['mobile'], $sms['code']);
        	    break;
        	case 'dispatching':
        	    $send_res = aliysms_helper::send_delivery($sms['mobile'], $sms['code']);
        	    break;
        	case 'sign_contract':
        	    $send_res = aliysms_helper::send_signed($sms['mobile'], $sms['code']);
        	    break;
        	case 'create_marketing':
        	    
        	    
        	    break;
        }
        
        
        
    }
    
    /**
     * 编辑
     */
    
    public function index()
    {
        $page          = Request::Get('page_no', 1);
        $status        = Request::Get('status', 5);
        $is_advenced   = Request::getParam('is_advenced', 0);
        $search_filter = Request::getParam('search_filter', array());
        
        // 拼装搜索条件
        $is_empty = 0;
        $filter = array();
        if (isset($search_filter['aliysms']) && $search_filter['aliysms']) {
            $filter['`content` LIKE '] = $search_filter['content'].'%';
        }
        
        if (isset($search_filter['mobile']) && $search_filter['mobile']) {
            $filter['mobile'] = $search_filter['mobile'];
        }
        
        if (isset($search_filter['start_date']) && $search_filter['start_date']) {
            $filter['add_time >='] = $search_filter['start_date'].' 00:00:00';
        }
        if (isset($search_filter['end_date']) && $search_filter['end_date']) {
            $filter['add_time <='] = $search_filter['end_date'].' 23:59:59';
        }
        
        if ($status == 0) {
        	$filter['`status` > '] = 0;
        } else {
            $filter['status'] = $status;
        }
        //分页
        $aliysms_count = _model('sms_status')->getTotal($filter);
        
        $aliysms_list = array();
        
        $aliysms_list = get_data_list('sms_status', $filter, ' ORDER BY `id` DESC ', $page, 20);
        
        foreach ($aliysms_list as $k=>$v) {
            $content = (array)json_decode($v['return_info']);
            if (is_array($content)) {
            	foreach ($content as $key=>$val) {
            	    $aliysms_list[$k]['return_info'] = array();
            	    $aliysms_list[$k]['return_info'][$key] = array();
            	    array_push($aliysms_list[$k]['return_info'][$key], $val);
            	}
            }
            $aliysms_list[$k]['content'] = (array)json_decode($v['content']);
        }
        
        
        Response::assign('sms_code_list', aliysms_config::$sms_code_list);
        Response::assign('aliysms_list', $aliysms_list);
        Response::assign('status', $status);
        Response::assign('search_filter', $search_filter);
        Response::assign('is_advenced', $is_advenced);
        
        Response::display('admin/aliysms_list.html');
    }
    
    /**
     * 更新
     */
    public function update()
    {
        
    }
    
    /**
     * 伪删除
     */
    public function delete()
    {
        $id = Request::getParam('id', '');
        
        
        
    }
    
    /**
     * 还原
     */
    public function change_status()
    {
        
    }
    
    /**
     * 销毁
     */
    public function delete_sms()
    {
        
    }
    
    
    
    
}